package com.ly.drivingschool.controller;

import com.ly.drivingschool.common.ResponseMessage;
import com.ly.drivingschool.pojo.Pager;
import com.ly.drivingschool.pojo.Setmeal;
import com.ly.drivingschool.pojo.Tweet;
import com.ly.drivingschool.service.SetmealService;
import com.ly.drivingschool.service.TweetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 消息管理
 */
@Slf4j
@RestController
@RequestMapping(value = "tweet",produces = "application/json; charset=utf-8")
public class TweetController {
    @Autowired
    private TweetService tweetService;

    /**
     * 分页查询
     * @param page
     * @param limit
     * @return
     */
    @GetMapping(value = "getPageTweetInfo")
    public ResponseMessage getPageTweetInfo(int page, int limit) {
        Pager<Tweet> pager = tweetService.findByPager(page,limit);
        System.out.println(pager);
        if (pager.getCount() == 0) {
            return ResponseMessage.createBySuccess("驾校暂无订阅信息",pager);
        } else {
            return ResponseMessage.createBySuccess(pager);
        }
    }

    /**
     * 模糊查询
     * @param page
     * @param limit
     * @param keyWork
     * @return
     */
    @GetMapping(value = "getKeyWorkTweetInfo")
    public ResponseMessage getKeyWorkTweetInfo(int page,int limit, String keyWork){
        Pager<Tweet> pager = tweetService.findByKey(page,limit,keyWork);
        if (pager.getCount() == 0) {
            return ResponseMessage.createBySuccess("驾校暂无该订阅信息,请检查",pager);
        } else {
            return ResponseMessage.createBySuccess(pager);
        }
    }

    /**
     * 删除一条记录
     * @param tweet_id
     * @return
     */
    @PostMapping(value = "delByIdSetmeal")
    public ResponseMessage delByIdSetmeal(int tweet_id) {
        int code = tweetService.deleteByPrimaryKey(tweet_id);
        return ResponseMessage.createBySuccess(code);
    }
}
